u "$data_clean_failure/riskdata_analysis_2004.dta",clear



* ------------------------------------------ *
*    			  bank size  	             *
* ------------------------------------------ *
// Tiny < $10 million
// smallish had $10-100M, 
// medium had $100M - $1 billion (B), 
// large had more than $1B in assets. 

gen small = assets <= 100
gen medium = assets > 100 & assets < 1000
gen large = assets > 1000
gen total = 1

local Size "total small medium large"



* ------------------------------------------ *
*          	DID on subprime lending   	     *
* ------------------------------------------ *
quietly{
	eststo clear
	local reg_results ""
	foreach size of local Size {
		eststo `size':reghdfe pct_subprime bank_pre bank $Institution_04 $Borrower $State if `size'==1,a(state_num year) vce(cluster id_num)
		estadd ysumm
		local reg_results "`reg_results' `size'"
	}
	estfe `reg_results', labels(state_num "State FE" id_num "Institutional FE" year "Year FE")
	noisily:esttab `reg_results' using "$regtables_failure/subprime_bysize.tex", ///
				indicate("Institution Characteristics = $Institution_04" ///
								 "Borrower Characteristics = $Borrower" ///
								 "State Controls = $State" `r(indicate_fe)', labels($\times$ " ")) ///
				replace lab compress gap booktab alignment(c) ///
				scalar("e(covariate)") ///
				stats(N r2 ymean, fmt(%9.0f %9.3f %9.3f) labels("$\mathnormal{N}$" "$\mathnormal{R^2}$" "Outcome mean")) ///
				cells(b(star fmt(4)) se(par fmt(4))) starlevels(* 0.10 ** 0.05 *** 0.01) ///	
				collabels(none) ///
				nobaselevels noomitted  nocons ///
				mtitles("whole sample" "small (10-100M)" "medium (100M-1B)" "large ($\geq$ 1B)" ) ///
				mgroups("Dependent Variable: Subprime Share (\%)" , pattern(1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))		
	estfe `reg_results', restore
}





* ------------------------------------------ *
*       DID on post-crisis performance       *
* ------------------------------------------ *
** relabel and rename to fit the table
ren netChargeOffRatio netChargeOff
local Performance "fail delqRatio netChargeOff"

la var delqRatio "deliquency"
la var netChargeOff "net charge-off"



quietly{
	eststo clear	
	local reg_results ""
	foreach size of local Size {
		eststo `size':reghdfe fail bank_crisis bank $Institution_04 $Borrower $State if `size'==1,a(state_num year) vce(cluster id_num)
		estadd ysumm
		local reg_results "`reg_results' `size'"
	}
	estfe `reg_results', labels(state_num "State FE" id_num "Institutional FE" year "Year FE")
	noisily:esttab `reg_results' using   "$regtables_failure/failure_bysize.tex", ///
				indicate("Institution Characteristics = $Institution_04" ///
								 "Borrower Characteristics = $Borrower" ///
								 "State Controls = $State" `r(indicate_fe)', labels($\times$ " ")) ///
				replace lab compress booktab gap alignment(c) ///
				scalar("e(covariate)") ///
				stats(N r2 ymean, fmt(%9.0f %9.3f %9.3f) labels("$\mathnormal{N}$" "$\mathnormal{R^2}$" "Outcome mean")) ///
				cells(b(star fmt(4)) se(par fmt(4))) starlevels(* 0.10 ** 0.05 *** 0.01) ///	
				collabels(none) ///
				nobaselevels noomitted  nocons ///
			mtitles("whole sample" "small (10-100M)" "medium (100M-1B)" "large ($\geq$ 1B)" ) ///
				mgroups("Dependent Variable: Failure Dummy" , pattern(1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))		
	estfe `reg_results', restore
}



